<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 签单客户 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <el-tabs v-model="activeName" @tab-click="tabClick">
        <el-tab-pane label="签约客户" name="7"></el-tab-pane>
        <el-tab-pane label="进件客户" name="8"></el-tab-pane>
        <el-tab-pane label="业绩核查" name="1"></el-tab-pane>
        <el-tab-pane label="作废记录" name="cancel"></el-tab-pane>
      </el-tabs>
      <div class="handle-box">
        <el-date-picker v-model="query.time" class="mr10" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        value-format="yyyy-MM-dd"></el-date-picker>
        <el-input v-model="query.kw" placeholder="请输入经理/客户姓名/电话查询" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="souClick">搜索</el-button>
      </div>
      <el-table v-loading="tableLoad" :data="tableData" border class="table" style="width: 100%" ref="multipleTable">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="cusName" label="客户姓名"></el-table-column>
        <el-table-column prop="cusPhone" label="电话"></el-table-column>
        <el-table-column prop="userName" label="签约经理"></el-table-column>
        <el-table-column prop="applyAmount" label="申请额度"></el-table-column>
        <el-table-column prop="intoAmount" label="进件额度"></el-table-column>
        <el-table-column prop="loanAmount" label="下款额度"></el-table-column>
        <el-table-column prop="deposit" label="诚意金"></el-table-column>
        <el-table-column prop="rate" label="费率"></el-table-column>
        <el-table-column prop="income" label="创收"></el-table-column>
        <el-table-column fixed="right" v-if="activeName == '1'" prop="auditUserName" label="审核人"></el-table-column>
        <el-table-column fixed="right" v-if="activeName == '1'" prop="auditTime" label="审核时间"></el-table-column>
        <el-table-column fixed="right" v-if="activeName == 'cancel'" prop="deleteReason" label="作废原因"></el-table-column>
        <el-table-column fixed="right" v-if="activeName == 'cancel'" prop="deleteUserName" label="作废操作人"></el-table-column>
        <el-table-column fixed="right" prop="fromName" label="创建时间"></el-table-column>
        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="seeClick(scope.row)">查看</el-button>
            <el-button v-if="activeName == '1' && scope.row.csAudit == 0" type="text" icon="el-icon-view"
                       @click="examineClick(scope.row.csId)">审核</el-button>
            <el-button v-if="activeName != 'cancel'" type="text" icon="el-icon-delete" @click="cancelClick(scope.row.csId)"
                       style="color:red">作废</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total,sizes, prev, pager, next" :current-page="query.page" :page-size="query.limit"
                       :page-sizes="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]" :total="query.totalCount" :pager-count="5"
                       @size-change="handlePageSelectChange" @current-change="handlePageChange" @prev-click="handlePageChange"
                       @next-click="handlePageChange"></el-pagination>
      </div>
    </div>
    <!-- 查看 -->
    <el-dialog title="查看详情" :visible.sync="seeFlg" width="40%">
      <el-descriptions class="margin-top" title="" size="medium" :column="3" border direction="vertical">
        <el-descriptions-item label="客户姓名">{{seeForm.cusName}}</el-descriptions-item>
        <el-descriptions-item label="电话">{{seeForm.cusPhone}}</el-descriptions-item>
        <el-descriptions-item label="签约经理" :span="2">{{seeForm.userName}}</el-descriptions-item>
        <el-descriptions-item label="申请额度">
          <el-tag size="small" type="">{{seeForm.applyAmount}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="进件额度">
          <el-tag v-if="seeForm.intoAmount" size="small" type="warning">{{seeForm.intoAmount}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="下款额度">
          <el-tag v-if="seeForm.loanAmount" size="small" type="success">{{seeForm.loanAmount}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="诚意金">
          <el-tag v-if="seeForm.deposit" size="small" type="warning">{{seeForm.deposit}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="费率">
          <el-tag size="small" type="warning">{{seeForm.rate}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="创收">
          <el-tag size="small" type="warning">{{seeForm.income}}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="合同照片">
          <el-image style="width: 50px; height: 50px" :src="seeForm.contractPic" :preview-src-list="[seeForm.contractPic]">
          </el-image>
        </el-descriptions-item>
        <el-descriptions-item label="诚意金截图">
          <el-image style="width: 50px; height: 50px" :src="seeForm.depositPic" :preview-src-list="[seeForm.depositPic]">
          </el-image>
        </el-descriptions-item>
        <el-descriptions-item label="创建时间">{{seeForm.createTime}}</el-descriptions-item>
        <el-descriptions-item label="备注">{{seeForm.remark}}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>
    <!-- 审核驳回原因 -->
    <el-dialog title="审核驳回原因" :visible.sync="rejectFlg" width="30%">
      <el-form ref="form" :model="rejectForm" label-width="50px">
        <el-form-item label="原因">
          <el-input type="textarea" v-model="rejectForm.txt"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="rejectFlg = false">取 消</el-button>
        <el-button type="primary" @click="examineFormSub" :loading="rejectLoad">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 作废说明 -->
    <el-dialog title="作废原因" :visible.sync="cancelFlg" width="30%">
      <el-form ref="form" :model="cancelForm" label-width="50px">
        <el-form-item label="原因">
          <el-input type="textarea" v-model="cancelForm.txt"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelFlg = false">取 消</el-button>
        <el-button type="primary" @click="cancelFormSub" :loading="cancelLoad">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { operateGetDataList, operateCancel, operateExamine } from '../../../api/index';
export default {
  data() {
    return {
      tableLoad: false,
      query: {
        page: 1,
        limit: 10,
        totalCount: 0,
        time: [],
        kw: ''
      },
      activeName: '7',
      tableData: [],

      seeFlg: false,
      seeForm: {},

      rejectFlg: false,
      rejectLoad: false,
      rejectForm: {
        id: '',
        type: '',
        txt: ''
      },

      cancelFlg: false,
      cancelLoad: false,
      cancelForm: {
        id: '',
        txt: ''
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    //初始化列表数据
    getList() {
      this.tableLoad = true;
      operateGetDataList({
        page: this.query.page,
        limit: this.query.limit,
        startTime: this.query.time ? this.query.time[0] : '',
        endTime: this.query.time ? this.query.time[1] : '',
        kw: this.query.kw,
        status: this.activeName != 'cancel' ? this.activeName : '',
        isDelete: this.activeName == 'cancel' ? '0' : '',
      }).then(res => {
        this.tableLoad = false;
        if (res.code == 0) {
          this.tableData = res.recordList;
          this.query.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //搜索
    souClick() {
      this.query.page = 1;
      this.getList();
    },
    //列表切换
    tabClick() {
      this.query.page = 1;
      this.getList();
    },
    //切换页数
    handlePageSelectChange(limit) {
      this.query.limit = limit;
      this.query.page = 1;
      this.getList();
    },
    //翻页
    handlePageChange(page) {
      thiss.query.page = page;
      this.getList();
    },
    //查看
    seeClick(item) {
      console.log(item);
      this.seeFlg = true;
      this.seeForm = item;
    },
    //审核
    examineClick(id) {
      this.rejectForm.id = id;
      this.$confirm('当前业绩信息无误，操作后不可变跟，确认审核通过吗？', '审核', {
        confirmButtonText: '通过',
        cancelButtonText: '驳回',
        type: 'warning'
      }).then(() => {
        this.rejectForm.type = 1;
        this.rejectForm.txt = "";
        this.examineFormSub();
      }).catch(() => {
        this.rejectForm.type = 2;
        this.rejectFlg = true;
      })
    },
    //审核提交
    examineFormSub() {
      this.rejectLoad = true;
      operateExamine({
        id: this.rejectForm.id,
        reason: this.rejectForm.txt,
        audit: this.rejectForm.type,
      }).then(res => {
        this.rejectLoad = false;
        if (res.code == 0) {
          this.$message.success("操作成功");
          this.rejectFlg = false;
          this.getList();
        } else {
          this.$message(res.msg);
        }
      })
    },
    //作废
    cancelClick(id) {
      this.$confirm('确认后不可变跟，确认作废吗？', '作废操作', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.cancelFlg = true;
        this.cancelForm.id = id;
      }).catch(() => {
      })
    },
    //提交作废
    cancelFormSub() {
      this.cancelLoad = true;
      operateCancel({
        id: this.cancelForm.id,
        reason: this.cancelForm.txt
      }).then(res => {
        this.cancelLoad = false;
        if (res.code == 0) {
          this.$message.success("操作成功");
          this.cancelFlg = false;
          this.getList();
        } else {
          this.$message(res.msg);
        }
      })
    }
  }
}
</script>
<style scoped>
.handle-input {
    width: 300px;
}
.mr10 {
    margin-right: 10px;
}
</style>